<?php

namespace app\controllers;

use yii\filters\auth\HttpBasicAuth;
use yii\web\Response;

use yii\rest\ActiveController;
use app\models\Country;

class UserController extends ActiveController {
    public $modelClass = 'app\models\Country';

    public function behaviors()
    {
        $behaviors = parent::behaviors();
        $auth = $behaviors['authenticator'];
        // $behaviors['contentNegotiator']['formats']['json'] = Response::FORMAT_JSON;
        unset($behaviors['authenticator']);
        // $behaviors['authenticator'] = [
        //     'class' => HttpBasicAuth::className(),
        // ];
        return $behaviors;
    }

    public function actions()
    {
        $actions = parent::actions();

        // 禁用"delete" 和 "create" 动作
        unset($actions['delete'], $actions['create']);

        // 使用"prepareDataProvider()"方法自定义数据provider 
        // $actions['index']['prepareDataProvider'] = [$this, 'prepareDataProvider'];

        return $actions;
    }

    public function prepareDataProvider()
    {
        // 为"index"动作准备和返回数据provider
    }

    public function actionIndex() {
        $res = Country::find()->asArray()->all();
        \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
        return res;
    }

    // public function actionView($id)
    // {
    //     return Country::findOne($id);
    // }


}